﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace 自定义多选下拉框;

public class MainWindowViewModel : ObservableObject
{
    private ObservableCollection<Company> _companies;
    private IList<Company> _selectedCompanies;

    public ObservableCollection<Company> Companies
    {
        get => _companies;
        set
        {
            if (_companies != value)
            {
                _companies = value;
                OnPropertyChanged();
            }
        }
    }

    public IList<Company> SelectedCompanies
    {
        get => _selectedCompanies;
        set
        {
            if (_selectedCompanies != value)
            {
                _selectedCompanies = value;
                OnPropertyChanged();
            }
        }
    }

    public MainWindowViewModel()
    {
        // 初始化公司列表
        Companies = new ObservableCollection<Company>
        {
            new Company
            {
                Name = "Company A",
                Age = 10,
                Address = "Address A"
            },
            new Company
            {
                Name = "Company B",
                Age = 15,
                Address = "Address B"
            },
            new Company
            {
                Name = "Company C",
                Age = 20,
                Address = "Address C"
            }
        };

        SelectedCompanies = new List<Company>();
    }
}
